$(document).ready(function () {
    showMenuInfo();
});

function showMenuInfo() {
    axios.get('/User/GetMenuInfo')
        .then(function (response) {
            $('#menu').html(response.data);
        })
}

function chooseInventory(inventoryId) {
    axios.post('/Inventory/ChooseInventory', $.param({
        inventoryId: inventoryId
    }))
        .then(function (response) {
            $('#right-top-content').html(response.data);
            $('#write-matter-content').html('');
            $('#show-matter-content').html('');
            $('#show-matter-remark').html('');
            $('#matter-date').html('<span onclick=\'getDetailMatter(0)\'><img id=\'detail\' src=\'/images/详细.png\' ></span>');
        })
}

function chooseMatter(matterId) {
    axios.post('/Matter/ChooseMatter', $.param({
        matterId: matterId
    }))
        .then(function (response) {
            $('#show-matter-content').html(response.data);
        })

    axios.post('/Matter/ShowMatterRemark', $.param({ matterId: matterId }))
        .then(function (response) {
            $('#left-bottom-title').html('<p id=\'matter-content\'>事项内容</p>' +
                '<a id=\'a-compile-matter\' href=\'/Matter/CompileMatterView?matterId=' + matterId + '\'><img id=\'compile-img-matter\' src=\'/images/编辑.png\'></a>' +
                '<span id=\'matter-date\'><span onclick=\'getDetailMatter(' + matterId + ')\'><img id=\'detail\' src=\'/images/详细.png\' ></span></span>');
            $('#show-matter-remark').html(response.data);
        })
}

function changeIsFinished(matterId) {
    axios.post('/Matter/ChangeIsFinished', $.param({ matterId: matterId }))
        .then(function (response) {
            $('#right-top-content').html(response.data);
        })
}

function getDetailMatter(matterId) {
    if (matterId != 0) {
        axios.post('/Matter/GetDetailMatter', $.param({ matterId: matterId }))
            .then(function (response) {
                $('#extend-box').html(response.data);
                showExtendBox();
            })
    }
}

function addMatter() {
    axios.get('/Matter/AddMatter')
        .then(function (response) {
            $('#extend-box').html(response.data);
            showExtendBox();
        })
}

function addInventory() {
    var typeId = $("#choose-type-box").val();
    var inventoryName = $('#form-set-name').val();
    slideUpType();
    //axios({
    //    url: '/Inventory/AddInventory',
    //    type: 'POST',
    //    data: $('#pull-down-form').serialize()
    //})
    axios.post('/Inventory/AddInventory', $.param({ typeId: typeId, inventoryName: inventoryName }))
        .then(function (response) {
            $('#inventorys').html(response.data);
            pullDownAdd();
        })
}

function addType() {
    var typeName = $('#input-create-type').val();
    var typeHtml = $("#pull-down-form").val();
    if (typeName.match(/\d+/g)) {
        alert('类型名称不能含有数字！');
        pullDownAdd();
        return;
    }
    //axios({
    //    url: '/Type/FoundType',
    //    type: 'POST',
    //    data: $('#pull-down-form').serialize()
    //})
    axios.post('/Type/FoundType', $.param({ typeName: typeName }))
        .then(function (response) {
            slideUpType();
            $('#inventorys').html(response.data);
            pullDownAdd();
        })
}

function deleteType(typeId) {
    if (confirm('确定删除该类型吗？')) {
        axios.post('/Type/DeleteType',
            $.param({
                typeId: typeId
            })
        )
            .then(function (response) {
                $('#inventorys').html(response.data);
            })
    }
}

function deleteInventory(inventoryID) {
    if (confirm('确定删除该清单吗？')) {
        axios.post('/Inventory/DeleteInventory',
            $.param({ inventoryId: inventoryID }))
            .then(function (response) {
                $('#inventorys').html(response.data);
                $('#right-top-content').html('');
                $('#show-matter-content').html('');
                $('#show-matter-remark').html('');
            })
    }
}

function deleteMatter(matterId) {
    if (confirm('确认删除该事项吗？')) {
        axios.post('/Matter/DeleteMatter',
            $.param({ matterId: matterId }))
            .then(function (response) {
                $('#right-top-content').html(response.data);
                $('#show-matter-content').html('');
                $('#show-matter-remark').html('');
            })
    }
}

function foundMatter() {
    var inventoryId = $('#extend-choose-inventory').val();
    var matterName = $('#extend-textarea-val').val();
    //axios({
    //    url: '/Matter/FoundMatter',
    //    type: 'POST',
    //    data: $('#form-found-matter').serialize()
    //})
    axios.post('/Matter/FoundMatter', $.param({ inventoryId: inventoryId, matterContent: matterName }))
        .then(function (response) {
            $('#right-top-content').html(response.data);
            concealExtendBox();
        })
}

function createType() {
    axios.get('/Type/AddTypeView')
        .then(function (response) {
            slideUpPullDownAdd();
            $('#pull-down-form').html(response.data);
            $('#pull-down-form').slideToggle('1000');
        })
}

function createInventory(typeId) {
    axios.post('/Inventory/AddInventoryView', $.param({ typeId: typeId }))
        .then(function (response) {
            slideUpPullDownAdd();
            $('#pull-down-form').html(response.data);
            $('#pull-down-form').slideToggle('1000');
        })
}